# coding: utf-8
import config.setting as setting
from gensim import corpora, models

# 加载模型
bow_dic = corpora.Dictionary.load(setting.FILE_ALL_DIC)
tfidf_model = models.TfidfModel.load(setting.FILE_TFIDF_MODEL)


def get_vec(seg_list):
    bow = bow_dic.doc2bow(seg_list)
    tfidf_tuple = tfidf_model[bow]
    tfidf_tuple.sort(key=lambda x: x[1], reverse=True)
    result = list()
    for t in tfidf_tuple:
        result.append('{word}/{tfidf}'.format(word=bow_dic.get(t[0]), tfidf=t[1]))
    return ' '.join(result)
